package com.ccjq.jq167.util;

import java.sql.*;

public class DbConnection {
    private static final String DRIVER;
    private static final String URL;
    private static final String USERNAME;
    private static final String PASSWORD;

    static {
        DbConfigReader dbConfigReader = new DbConfigReader();
        DRIVER = dbConfigReader.getValue("driver");
        URL = dbConfigReader.getValue("url");
        USERNAME = dbConfigReader.getValue("username");
        PASSWORD = dbConfigReader.getValue("password");
    }
    public static Connection getConnection(){
        Connection con = null;
        try {
            Class.forName(DRIVER);
            con = DriverManager.getConnection(URL,USERNAME,PASSWORD);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return con;
    }

    public static void close(ResultSet rs, Statement st, Connection con){
        try {
            if (rs!=null){
                rs.close();
            }
            if(st!=null){
                st.close();
            }
            if(con!=null){

                con.close();
            }

        }catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

